<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>鼠标滑过显示详情</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .box {
      /* CSS3新盒子模型属性: 控制width/height是盒子最终的宽高 */
      box-sizing: border-box;
      margin: 20px auto;
      width: 200px;
      height: 40px;
      line-height: 40px;
      text-align: center;
      border: 1px solid lightcoral;
      position: relative;
      cursor: pointer;
    }
    .box .detail {
      /* display: none; */
      position: absolute;
      right: -1px;
      top: 38px;
      z-index: -1;
      box-sizing: border-box;
      width: 500px;
      height: 100px;
      line-height: 100px;
      text-align: center;      
      border: 1px solid lightcoral;
    }
  </style>
</head>
<body>
  <!-- 基于CSS实现, 我们需要让详情区域时按钮的子元素 -->
  <div class="box" id="box">
    <span>购物车</span>
    <div class="detail" id="detail" style="display: none;">
      购物车的相关信息
    </div>
  </div>
  <!-- 
      传统基于操作DOM的方式实现业务需求
      1.想操作谁就先获取谁
      2. 给某元素绑定某事件
      3.在事件触发的时候修改元素的样式等
   -->
  <!-- <script>
    let box = document.getElementById('box');
    let detail = document.getElementById('detail');
    box.onclick = function() {
      // 操作的元素行内样式, 如果我们没有把样式写在行内上, 在JS中基于.style.xxx的方式是无法获取到样式的
      // 1.首先获取detail原有的样式(显示还是隐藏)
      let n = detail.style.display;
      if(n === "none") {
        detail.style.display = "block";
        box.style.borderBottomColor = '#fff';
      }else {
        detail.style.display = "none";
        box.style.borderBottomColor = 'lightcoral'
      }
      
    }
  </script> -->
  <script>
    let box = document.getElementById('box');
    let detail = document.getElementById('detail');
    box.onclick = function() {
      let n = detail.style.display;
      if(n === 'none') {
        detail.style.display = 'block';
        box.style.borderBottomColor = '#fff'
      }else {
        detail.style.display = 'none';
        box.style.borderBottomColor = 'lightcoral'
      }
    }
  </script>
</body>
</html>